#include "scene/camera.h"
#include "core/message.h"

#include "app/testengine.h"

#include <SDL/SDL.h>

namespace test {
	using engine::scene::Camera;
	using engine::core::Message;
	
	TestApp::TestApp() {
		
	}
	
	TestApp::~TestApp() {
		
	}
	
	bool TestApp::initialize() {
		getEngine()->getSceneManager()->setSkyBox(true, "textures/sky");
		getEngine()->getSceneManager()->setWorldGeometry("maps/charon3dm11v2.bsp");
		
		shared_ptr<Camera> c = getEngine()->getSceneManager()->createCamera("main");
		getEngine()->getSceneManager()->setActiveCamera("main");
		c->setFixedYawAxis(true, slVec3::UNIT_Y);
			
		return true;
	}
	 
	bool TestApp::prepare(float dT) {
		return true;
	}
	
	void TestApp::update() {
		
	}
	
	void TestApp::shutdown() {
		
	}
	
	bool TestApp::processRecievedMessage(shared_ptr<Message> msg) {
		if (msg->m_Type == MT_KEY_PRESS) {
			if (msg->key.m_State == 1) {
				switch(msg->key.m_Key) {
					case SDLK_LEFT:
						getEngine()->getSceneManager()->getActiveCamera()->yaw(1.0f);
					break;
					case SDLK_RIGHT:
						getEngine()->getSceneManager()->getActiveCamera()->yaw(-1.0f);
					break;
					case SDLK_UP:
						getEngine()->getSceneManager()->getActiveCamera()->pitch(1.0f);
					break;
					case SDLK_DOWN:
						getEngine()->getSceneManager()->getActiveCamera()->pitch(-1.0f);
					break;
				}
			}
		}
		
		return false;
	}
		
}
